const Mock = require('mockjs')
const random = Mock.Random

let userList = []

for (let i = 0; i < 100; i++) {
    userList.push({
        id: i + 1001,
        name: random.cname(),
        age: random.integer(18, 60),
        address: random.county(true),
        phone: random.string('number', 11)
    })
}

const deleteFn = (param, fn) => {
    for (let key in param) {
        if (userList && userList.length > 0) {
            if (!(key in userList[0])) {
                fn(`${key}字段不存在`)
                return
            }
        } else {
            fn('暂无数据，无法删除')
            return
        }
    }
    for (let key in param) {
        userList = userList.filter(item => {
            return item[key] != param[key]
        })
        fn('删除成功')
    }
}

module.exports = {
    userList,
    deleteFn
}
